package com.weipeep.sys.controller;


import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weipeep.sys.domain.NavigateMenuDO;
import com.weipeep.sys.service.NavigateMenuService;
import com.weipeep.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2019-08-19 21:33:54 | wangyun</small>
 */
@Controller
@RequestMapping("/sys/navigateMenu")
public class NavigateMenuController {
	@Autowired
	private NavigateMenuService navigateMenuService;
	
	@GetMapping()
	@RequiresPermissions("sys:navigateMenu:navigateMenu")
	String NavigateMenu(){
	    return "sys/navigateMenu/navigateMenu";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("sys:navigateMenu:navigateMenu")
	public Result<IPage<NavigateMenuDO>> list(Integer pageNumber, Integer pageSize, NavigateMenuDO navigateMenuDTO){
		// 查询列表数据
        IPage<NavigateMenuDO> page = new Page<>(pageNumber, pageSize);
        
        Wrapper<NavigateMenuDO> wrapper = new QueryWrapper<NavigateMenuDO>(navigateMenuDTO);
        page = navigateMenuService.page(page, wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("sys:navigateMenu:add")
	String add(){
	    return "sys/navigateMenu/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("sys:navigateMenu:edit")
	String edit(@PathVariable("id") Long id,Model model){
		NavigateMenuDO navigateMenu = navigateMenuService.getById(id);
		model.addAttribute("navigateMenu", navigateMenu);
	    return "sys/navigateMenu/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("sys:navigateMenu:add")
	public Result<String> save( NavigateMenuDO navigateMenu){
		if(navigateMenuService.save(navigateMenu)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("sys:navigateMenu:edit")
	public Result<String>  update( NavigateMenuDO navigateMenu){
		navigateMenuService.updateById(navigateMenu);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("sys:navigateMenu:remove")
	public Result<String>  remove( Long id){
		if(navigateMenuService.removeById(id)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("sys:navigateMenu:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		navigateMenuService.removeByIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
